#!/bin/bash

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# author:         Maoyuchen                                                       @
# Creation Time:  2022-10-02                                                      @
# Purpose:        This shell will creat some users automatically                  @
#                 The relevant detail are as follow, please read carefully        @
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


echo "You can create as many user as the number which is you enter"
echo "User name can  only  enter string and number can only enter number"

read -p "Please keyin number:" num
if [[ ! ${num} =~ ^[0-9]+$ ]]; then
  echo "Input number ERROR!"
  exit 1
fi

read -p "Please keyin userName:" user
if [[ -z ${user} ]] && [[ ${user} =~ ^[a-z]+$ ]]; then
  echo "Input string ERROR!"
  exit 1
fi

for i in $(seq -w ${num});
do
  echo "creating user ${user}${i}"
  useradd ${user}${i} >> /dev/null
  passWord=$(openssl rand -base64 16)
  echo "${passWord}" | passwd --stdin ${user}${i}
  echo -e "The user is:\033[32m${user}${i}\033[0m and the passwd is:\033[32m${passWord}\033[0m \n"
  sleep 1
done
